// pages/warning/warninginfo.js
import http from '../../http/http.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    popup:false,
    alertpop:false,
    list:{},
    popmes:'',
    id:'',
    apiary:{},
    radioactive:0,
    apiaryid:'',
    beeid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdata()
  },
  getdata:function(){
    http.getdata('/api/monitor/list?status=1').then((res)=>{
     this.setData({
       list: res.data.result
     })
    })
  },
  // 所有蜂场
  choice_bee:function(){
    this.setData({
      popup: true
    })
    http.getdata('/api/apiary/list').then((res)=>{
     this.setData({
       apiary:res.data.result
     })
    })
    
  },
  // 弹框取消
  cancel:function(){
    this.setData({
      popup: false
    })
  },
  //弹框确认
  sure: function () {
    http.getdata('/api/monitor/list?status=1&apiaryId=' + this.data.apiaryid).then((res) => {
      this.setData({
        list: res.data.result,
        popup: false
      })
    })
  },
  // 查看
  viewbee:function(e){
    console.log(e)
    let ids = e.currentTarget.dataset.id
    let mesage = e.currentTarget.dataset.message
    let beeid = e.currentTarget.dataset.beeid
    this.setData({
      alertpop: true,
      popmes:mesage,
      id: ids,
      beeid: beeid
    })
  },
  // 单选
  changeradio:function(e){
    let index = e.currentTarget.dataset.index;
    let apiaryID = e.currentTarget.dataset.id
    this.setData({
      radioactive:index,
      apiaryid: apiaryID
    })
  },
  // 关闭查看
  closepop:function(){
    let pars = {
      id: this.data.id
    }
    http.putdata('/api/monitor/process',pars).then((res)=>{
      this.setData({
        alertpop: false
      })
      http.getdata('/api/monitor/list?status=1&apiaryId=' + this.data.beeid).then((res) => {
        this.setData({
          list: res.data.result,
        })
      })
    })
  }
})